package net.sourceforge.krama.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang.StringUtils;

/**
 * 
 * @author chabane
 *
 */
public class TUtil {

	public static final String HORIZONTAL_PANEL = "krama-horizontalPanel";
	public static final String VERTICAL_PANEL = "krama-VerticalPanel";
	public static boolean javascriptShouldBeAvailable = false;
	public static boolean prototypeShouldBeAvailable = false;
	public static boolean jQueryShouldBeAvailable = false;
	public static boolean doJoShouldBeAvailable = false;
	public static boolean domDragShouldBeAvailable = false;
	public static boolean clicShouldBeAvailable = false;
	
	public static boolean stringOk(String chaine) {

		if (chaine != null && !StringUtils.isEmpty(chaine)) {
			return true;
		}
		return false;
	}

	public static boolean listOk(List list) {

		if (list != null && !list.isEmpty()) {
			return true;
		}
		return false;
	}

	public static void writeInFile(String file, String source)
			throws IOException {

		FileWriter fw = new FileWriter(file);
		fw.write(source);
		fw.flush();
		fw.close();
	}

	public static String horizontalEncapsulate(String html) {

		return "<div class='"+HORIZONTAL_PANEL+"'>" + html + "</div>";
	}

	public static String VerticalEncapsulate(String html) {

		return "<div class='"+VERTICAL_PANEL+"'>" + html + "</div>";
	}
	
	/**
	 * This Method determinate if a kind of attributValue is a same that param
	 * @param attributeValue
	 * @param param
	 * @return boolean
	 */
	public static boolean isSameKind(String attributeValue, Object param) {
		
		if(attributeValue.equals("java.lang.String") && param == null){
			return true;
		}else if(attributeValue.equals("java.lang.Boolean") && param instanceof Boolean){
			return true;
		}else if (attributeValue.equals("java.lang.Long") && param instanceof Long){
			return true;
		}else if (attributeValue.equals("java.lang.String") && param instanceof String){
			return true;
		}else if (attributeValue.equals("java.lang.Float") && param instanceof Float){
			return true;
		}else if (attributeValue.equals("java.lang.Double") && param instanceof Double){
			return true;
		}else if (attributeValue.equals("java.lang.Integer") && param instanceof Integer){
			return true;
		}else if (attributeValue.equals("java.lang.Byte") && param instanceof Byte){
			return true;
		}else if (attributeValue.equals("java.lang.Character") && param instanceof Character){
			return true;
		}else if (attributeValue.equals("java.lang.Short") && param instanceof Short){
			return true;
		}

	return false;
}
}
